#Customisable stuff here
LINUX32_COMPILER = gcc #i686-pc-linux-gnu-gcc
LINUX64_COMPILER = x86_64-linux-gnu-gcc
WIN32_COMPILER = gcc.exe #/usr/bin/i586-mingw32msvc-gcc
WIN32_WINDRES = i586-mingw32msvc-windres
#LINUX_ARM_COMPILER = arm-pc-linux-gnu-gcc
LINUX_ARM_COMPILER = arm-none-linux-gnueabi-gcc
LINUX_PPC_COMPILER = powerpc-unknown-linux-gnu-gcc
FREEBSD60_COMPILER = i686-pc-freebsd6.0-gcc
MACPORT_COMPILER = i686-apple-darwin10-gcc-4.0.1

LIBPURPLE_CFLAGS = -I/usr/include/libpurple -I/usr/local/include/libpurple -I./../.. -DPURPLE_PLUGINS -DENABLE_NLS -DHAVE_ZLIB
GLIB_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include #	-I/usr/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/include/json-glib-1.0 
#$(pkg-config --cflags glib-2.0)
#-ljson-glib-1.0
WIN32_DEV_DIR = ../../../../win32-dev
WIN32_PIDGIN_DIR = ../../../../pidgin-2.7.11
WIN32_GTK_DIR = ${WIN32_DEV_DIR}/gtk_2_0-2.22.1
WIN32_CFLAGS = -I${WIN32_GTK_DIR}/include/glib-2.0 -I${WIN32_PIDGIN_DIR}/libpurple/win32 -I${WIN32_GTK_DIR}/include -I${WIN32_GTK_DIR}/include/glib-2.0 -I${WIN32_GTK_DIR}/lib/glib-2.0/include -I/usr/include/json-glib-1.0
WIN32_LIBS = -L${WIN32_GTK_DIR}/lib -L${WIN32_PIDGIN_DIR}/libpurple -lglib-2.0 -lgobject-2.0 -lintl -lpurple -lws2_32 -L. -lz
#-lzlib1
MACPORT_CFLAGS = -I/opt/local/include/libpurple -DPURPLE_PLUGINS -DENABLE_NLS -DHAVE_ZLIB -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include -I/opt/local/include/json-glib-1.0 -arch i386 -arch ppc -dynamiclib -L/opt/local/lib -ljson-glib-1.0 -lpurple -lglib-2.0 -lgobject-2.0 -lintl -lz -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4

DEB_PACKAGE_DIR = ./debdir

BELUGA_SOURCES =   libbeluga.c \
		   libbeluga.h \
		   BelugaAccount.c \
		   BelugaAccount.h \
		   BelugaLog.h \
		   BelugaPod.c \
		   BelugaPod.h \
		   BelugaProtocol.c \
		   BelugaProtocol.h \
		   BelugaUpdate.c \
		   BelugaUpdate.h \
		   beluga_connection.c \
		   beluga_connection.h \
		   beluga_json.c \
		   beluga_json.h \
		   beluga_html.c \
	 	   beluga_html.h

#Standard stuff here
.PHONY:	all clean install sourcepackage

beluga:	libbeluga.so
	cp libbeluga.so ~/.purple/plugins/

beluga64:
	libbeluga64.so
	cp libbeluga64.so ~/.purple/plugins/

all:	libbeluga.so libbeluga.dll libbeluga64.so libbelugaarm.so libbelugappc.so installers sourcepackage
all:	libbeluga.so libbeluga.dll

install:
	cp libbeluga.so /usr/lib/purple-2/
	cp libbeluga64.so /usr/lib64/purple-2/
	cp beluga16.png /usr/share/pixmaps/pidgin/protocols/16/beluga.png
	cp beluga22.png /usr/share/pixmaps/pidgin/protocols/22/beluga.png
	cp beluga48.png /usr/share/pixmaps/pidgin/protocols/48/beluga.png
	cp beluga.svg /usr/share/pixmaps/pidgin/protocols/scalable/beluga.svg
#cp libbelugaarm.so /usr/lib/pidgin/
#cp libbelugappc.so /usr/lib/purple-2/

installers:	purple-beluga.exe purple-beluga.deb purple-beluga.tar.bz2

clean:
	rm -f libbeluga.so libbeluga.dll libbeluga64.so libbelugaarm.so libbelugappc.so purple-beluga.exe purple-beluga.deb purple-beluga.tar.bz2 purple-beluga-source.tar.bz2
	rm -rf purple-beluga

libbeluga.so:	${BELUGA_SOURCES}
	${LINUX32_COMPILER} ${LIBPURPLE_CFLAGS} -Wall ${GLIB_CFLAGS} -I. -g -O2 -pipe ${BELUGA_SOURCES} -o libbeluga.so -shared -fPIC -DPIC

#libbelugaarm.so:	${BELUGA_SOURCES}
#	${LINUX_ARM_COMPILER} ${LIBPURPLE_CFLAGS} -Wall ${GLIB_CFLAGS} -I. -g -O2 -pipe ${BELUGA_SOURCES} -o libbelugaarm.so -shared -fPIC -DPIC

libbeluga64.so:	${BELUGA_SOURCES}
	${LINUX64_COMPILER} ${LIBPURPLE_CFLAGS} -Wall ${GLIB_CFLAGS} -I. -g -m64 -O2 -pipe ${BELUGA_SOURCES} -o libbeluga64.so -shared -fPIC -DPIC
#
#libbelugappc.so:	${BELUGA_SOURCES}
#	${LINUX_PPC_COMPILER} ${LIBPURPLE_CFLAGS} -Wall ${GLIB_CFLAGS} -I. -g -O2 -pipe ${BELUGA_SOURCES} -o libbelugappc.so -shared -fPIC -DPIC
#
libbelugamacport.so: ${BELUGA_SOURCES}
	${MACPORT_COMPILER} ${MACPORT_CFLAGS} -Wall -I. -g -O2 -pipe ${BELUGA_SOURCES} -o libbelugamacport.so -shared
#
#purple-beluga.res:	purple-beluga.rc
#	${WIN32_WINDRES} $< -O coff -o $@

libbeluga.dll:	${BELUGA_SOURCES}
	${WIN32_COMPILER} ${LIBPURPLE_CFLAGS} -Wall -I. -g -O2 -pipe ${BELUGA_SOURCES} -o $@ -shared -mno-cygwin ${WIN32_CFLAGS} ${WIN32_LIBS} -Wl,--strip-all
	upx libbeluga.dll

libbeluga-debug.dll:	${BELUGA_SOURCES}
	${WIN32_COMPILER} ${LIBPURPLE_CFLAGS} -Wall -I. -g -O2 -pipe ${BELUGA_SOURCES} -o $@ -shared -mno-cygwin ${WIN32_CFLAGS} ${WIN32_LIBS}
#
#libbelugabsd60.so:	${BELUGA_SOURCES}
#	${FREEBSD60_COMPILER} ${LIBPURPLE_CFLAGS} -Wall ${GLIB_CFLAGS} -I. -g -O2 -pipe ${BELUGA_SOURCES} -o libbeluga.so -shared -fPIC -DPIC


purple-beluga.exe:	libbeluga.dll
	echo "Dont forget to update version number"
	makensis beluga.nsi > /dev/null

purple-beluga.deb:	libbeluga.so libbelugaarm.so libbeluga64.so libbelugappc.so
	echo "Dont forget to update version number"
	cp libbeluga.so ${DEB_PACKAGE_DIR}/usr/lib/purple-2/
	cp libbelugappc.so ${DEB_PACKAGE_DIR}/usr/lib/purple-2/
	cp libbeluga64.so ${DEB_PACKAGE_DIR}/usr/lib64/purple-2/
	cp libbelugaarm.so ${DEB_PACKAGE_DIR}/usr/lib/pidgin/
	cp beluga16.png ${DEB_PACKAGE_DIR}/usr/share/pixmaps/pidgin/protocols/16/beluga.png
	cp beluga22.png ${DEB_PACKAGE_DIR}/usr/share/pixmaps/pidgin/protocols/22/beluga.png
	cp beluga48.png ${DEB_PACKAGE_DIR}/usr/share/pixmaps/pidgin/protocols/48/beluga.png
	cp beluga.svg ${DEB_PACKAGE_DIR}/usr/share/pixmaps/pidgin/protocols/scalable/beluga.svg
	chown -R root:root ${DEB_PACKAGE_DIR}
	chmod -R 755 ${DEB_PACKAGE_DIR}
	dpkg-deb --build ${DEB_PACKAGE_DIR} $@ > /dev/null

purple-beluga.tar.bz2:	purple-beluga.deb
	tar --bzip2 --directory ${DEB_PACKAGE_DIR} -cf $@ usr/

sourcepackage:	${BELUGA_SOURCES} Makefile beluga16.png beluga22.png beluga48.png beluga.svg COPYING beluga.nsi
	tar -cf tmp.tar $^
	mkdir purple-beluga
	mv tmp.tar purple-beluga
	tar xvf purple-beluga/tmp.tar -C purple-beluga
	rm purple-beluga/tmp.tar
	tar --bzip2 -cf purple-beluga-source.tar.bz2 purple-beluga
	rm -rf purple-beluga
